package com.dz.lm.service.comp.remark.impl;

import com.dz.lm.common.exception.ServiceException;
import com.dz.lm.common.util.FileUploadUtil;
import com.dz.lm.common.util.StringUtil;
import com.dz.lm.dao.compremark.read.CompRemarkDao;
import com.dz.lm.domain.compremark.CompRemark;
import com.dz.lm.domain.compremark.CompRemarkExample;
import com.dz.lm.service.comp.remark.CompRemarkService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CompRemarkServiceImpl implements CompRemarkService {
    @Resource(name = "readCompRemarkDao")
    private CompRemarkDao readCompRemarkDao;
    @Resource(name = "writeCompRemarkDao")
    private com.dz.lm.dao.compremark.write.CompRemarkDao writeCompRemarkDao;
    @Override
    public int add(CompRemark remark) throws ServiceException {
        return writeCompRemarkDao.insertSelective(remark);
    }

    @Override
    public int update(CompRemark remark) throws ServiceException {
        return writeCompRemarkDao.updateByPrimaryKeySelective(remark);
    }

    @Override
    public int delete(int remarkId) throws ServiceException {
        return writeCompRemarkDao.deleteByPrimaryKey(remarkId);
    }

    @Override
    public CompRemark get(int objId, int type) throws ServiceException {
        CompRemark remark = null;
        CompRemarkExample ex = new CompRemarkExample();
        CompRemarkExample.Criteria cr = ex.createCriteria();
        cr.andObjIdEqualTo(objId);
        cr.andTypeEqualTo(type);
        List<CompRemark> remarks = readCompRemarkDao.selectByExample(ex);
        if(remarks != null && remarks.size() > 0){
            remark= remarks.get(0);
        }
        return remark;
    }
}
